package com.example.qixinshangwutong.model.home;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.qixinshangwutong.R;
import com.example.qixinshangwutong.view.activity.CompanyActivity;

import org.jetbrains.annotations.NotNull;

import java.util.List;

public class RecycleAdapter extends RecyclerView.Adapter <RecycleAdapter.myHolder>{
    private Context context;
    private List<RecycleTextModel> data;

    public void setData(List<RecycleTextModel> data) {
        this.data = data;
    }

    public RecycleAdapter(Context context) {
        this.context = context;
    }

    @NonNull
    @NotNull
    @Override
    public myHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
        return new myHolder(LayoutInflater.from(context).inflate(R.layout.recycle_item,null));
    }

    @Override
    public void onBindViewHolder(@NonNull @NotNull myHolder holder, int position) {
        holder.textView.setText(data.get(position).getName());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context, CompanyActivity.class);
                intent.putExtra("url","http://m.qxswt.com/company/"+data.get(position).getId());
                intent.putExtra("name",data.get(position).getName());
                intent.putExtra("murl",data.get(position).getUrl());
                context.startActivity(intent);
            }
        });

    }


    @Override
    public int getItemCount() {
        return null!=data?data.size():0;
    }
    class myHolder extends RecyclerView.ViewHolder{
        TextView textView;

        public myHolder(@NonNull @NotNull View itemView) {
            super(itemView);
            textView=itemView.findViewById(R.id.recycle_text);
        }
    }

}
